home *** CD-ROM | disk | FTP | other *** search
/ Chip: Internet / Chip Internet.iso / viewer / sox7dos / sbdsp.c < prev    next >
Text File  |  1993-02-11  |  3KB  |  153 lines

  1. #if    defined(BLASTER) || defined(SBLAST)
  2. /*
  3.  * Copyright 1992 Rick Richardson
  4.  * Copyright 1991 Lance Norskog And Sundry Contributors
  5.  * This source code is freely redistributable and may be used for
  6.  * any purpose.  This copyright notice must be maintained. 
  7.  * Rick Richardson, Lance Norskog And Sundry Contributors are not
  8.  * responsible for the consequences of using this software.
  9.  */
  10.  
  11. /*
  12.  * Direct to Sound Blaster device driver.
  13.  * SBLAST patches by John T. Kohl.
  14.  */
  15.  
  16. #include <sys/types.h>
  17. #ifdef SBLAST
  18. #include <i386/isa/sblast.h>
  19. #else
  20. #include <sys/sb.h>
  21. #endif
  22. #include <signal.h>
  23. #include "st.h"
  24.  
  25. /* Private data for SKEL file */
  26. typedef struct sbdspstuff {
  27.     int    samples;        /* bytes remaining in current block */
  28. } *sbdsp_t;
  29.  
  30. IMPORT float volume, amplitude;
  31. IMPORT int summary, verbose;
  32.  
  33. static got_int = 0;
  34.  
  35. static void
  36. sigint(s)
  37. {
  38.     if (s) got_int = 1;
  39.     else signal(SIGINT, sigint);
  40. }
  41.  
  42. /*
  43.  * Do anything required before you start reading samples.
  44.  * Read file header. 
  45.  *    Find out sampling rate, 
  46.  *    size and style of samples, 
  47.  *    mono/stereo/quad.
  48.  */
  49. sbdspstartread(ft) 
  50. ft_t ft;
  51. {
  52.     sbdsp_t sbdsp = (sbdsp_t) ft->priv;
  53.     int off = 0;
  54.  
  55.     /* If you need to seek around the input file. */
  56.     if (0 && ! ft->seekable)
  57.         fail("SKEL input file must be a file, not a pipe");
  58.  
  59.     if (!ft->info.rate)
  60.         ft->info.rate = 11000;
  61.     ft->info.size = BYTE;
  62.     ft->info.style = UNSIGNED;
  63.     ft->info.channels = 1;
  64.     ioctl(fileno(ft->fp), DSP_IOCTL_RESET, 0);
  65. #ifdef SBLAST
  66.     ioctl(fileno(ft->fp), DSP_IOCTL_VOICE, &off);
  67.     ioctl(fileno(ft->fp), DSP_IOCTL_SPEED, &ft->info.rate);
  68. #else
  69.     ioctl(fileno(ft->fp), DSP_IOCTL_VOICE, 0);
  70.     ioctl(fileno(ft->fp), DSP_IOCTL_SPEED, ft->info.rate);
  71. #endif
  72.     sigint(0);    /* Prepare to catch SIGINT */
  73. }
  74.  
  75. /*
  76.  * Read up to len samples from file.
  77.  * Convert to signed longs.
  78.  * Place in buf[].
  79.  * Return number of samples read.
  80.  */
  81.  
  82. sbdspread(ft, buf, len) 
  83. ft_t ft;
  84. long *buf, len;
  85. {
  86.     sbdsp_t sbdsp = (sbdsp_t) ft->priv;
  87.     int        rc;
  88.  
  89.     if (got_int) return (0);
  90.     rc = rawread(ft, buf, len);
  91.     if (rc < 0) return 0;
  92.     return (rc);
  93. }
  94.  
  95. /*
  96.  * Do anything required when you stop reading samples.  
  97.  * Don't close input file! 
  98.  */
  99. sbdspstopread(ft) 
  100. ft_t ft;
  101. {
  102. #ifdef SBLAST
  103.     ioctl(fileno(ft->fp), DSP_IOCTL_FLUSH, 0);
  104. #endif
  105. }
  106.  
  107. sbdspstartwrite(ft) 
  108. ft_t ft;
  109. {
  110.     sbdsp_t sbdsp = (sbdsp_t) ft->priv;
  111.     int on = 1;
  112.  
  113.     /* If you have to seek around the output file */
  114.     if (0 && ! ft->seekable)
  115.         fail("Output .sbdsp file must be a file, not a pipe");
  116.  
  117.     if (!ft->info.rate)
  118.         ft->info.rate = 11000;
  119.     ft->info.size = BYTE;
  120.     ft->info.style = UNSIGNED;
  121.     ft->info.channels = 1;
  122.     ioctl(fileno(ft->fp), DSP_IOCTL_RESET, 0);
  123. #ifdef SBLAST
  124.     ioctl(fileno(ft->fp), DSP_IOCTL_FLUSH, 0);
  125.     ioctl(fileno(ft->fp), DSP_IOCTL_VOICE, &on);
  126.     ioctl(fileno(ft->fp), DSP_IOCTL_SPEED, &ft->info.rate);
  127. #else
  128.     ioctl(fileno(ft->fp), DSP_IOCTL_VOICE, 1);
  129.     ioctl(fileno(ft->fp), DSP_IOCTL_SPEED, ft->info.rate);
  130. #endif
  131. }
  132.  
  133. sbdspwrite(ft, buf, len) 
  134. ft_t ft;
  135. long *buf, len;
  136. {
  137.     sbdsp_t sbdsp = (sbdsp_t) ft->priv;
  138.  
  139.     if (len == 0) return 0;
  140.     return (rawwrite(ft, buf, len));
  141. }
  142.  
  143. sbdspstopwrite(ft) 
  144. ft_t ft;
  145. {
  146.     /* All samples are already written out. */
  147.     /* If file header needs fixing up, for example it needs the */
  148.      /* the number of samples in a field, seek back and write them here. */
  149.     fflush(ft->fp);
  150.     ioctl(fileno(ft->fp), DSP_IOCTL_FLUSH, 0);
  151. }
  152. #endif
  153.